import { getCarIcon, getOrderIcon } from './Icon'
import { getCarMenu, getOrderMenu } from './contextMenu'
export const createCarMarker = (map, car, controlStatus, menuClick, markerClick) => {
  var menu = getCarMenu(car, menuClick)

  var marker = new AMap.Marker({
    position: [car.lon, car.lat],
    icon: getCarIcon(car), // 添加 Icon 实例
    title: car.plateNumber,
    zoom: 11

  })

  // setInterval(() => {
  //   // var index = marker.index
  //   // var iconUrl = index === 1 ? 'static/amap/car_1.png' : 'static/amap/car_2.png'
  //   var icon = new AMap.Icon({
  //     image: 'static/amap/car_3.png', // Icon的图像
  //     imageSize: new AMap.Size(30, 32) // 根据所设置的大小拉伸或压缩图片
  //   })
  //   marker.setIcon(icon)
  // }, 1000)

  marker.on('click', (e) => {
    markerClick(car)
  })
  if (controlStatus === 0) {
    marker.on('rightclick', function(e) {
      menu.open(map, e.lnglat)
    })
  } else {
    marker.setLabel({
      offset: new AMap.Pixel(0, 40),
      content: "<div class='carInfo'> <span style='color: blue;'>" + car.plateNumber + "</span><span style='color: red; margin-left: 5px'>" + car.temperature01 + '°C</span></div>'
    })
  }

  map.add(marker)
  map.setFitView()// 适配所有标记点
  // var zoom = Math.floor(Math.random() * 7) + 11
  // map.setZoomAndCenter(zoom,  [ car.lon,car.lat]);

  // // map.panTo(car.position);//平行
  // setTimeout(()=>{
  //     map.setFitView();//适配所有标记点
  // },2000)

  return marker
}

export const createOrderMarker = (map, order, controlStatus, mClieck) => {
  var menu = getOrderMenu(order, mClieck)
  var marker = new AMap.Marker({

    position: [order.longitude, order.latitude],
    icon: getOrderIcon(order), // 添加 Icon 实例
    title: order.shipAddress,
    zoom: 11

  })
  marker.on('rightclick', function(e) {
    menu.open(map, e.lnglat)
  })

  if (controlStatus === 1) {
    var infoHtml = "<div class='orderInfo'>"
    infoHtml += "<span style='color: blue;'>" + order.totlaPrice + 'RMB</span>'
    infoHtml += "<span style='color: red;margin-left: 5px'>" + order.carOcMin + '~' + order.carOcMax + '°C</span>'
    marker.setLabel({
      offset: new AMap.Pixel(0, 40),
      content: infoHtml
    })
  }

  map.add(marker)
  map.setFitView()// 适配所有标记点
  // var zoom = Math.floor(Math.random() * 7) + 11
  // map.setZoomAndCenter(zoom,  [ car.lon,car.lat]);

  // // map.panTo(car.position);//平行
  // setTimeout(()=>{
  //     map.setFitView();//适配所有标记点
  // },2000)
  return marker
}
